import DialogBaseUI from "./DialogBaseUI";

export enum HINT_TYPE{
    ONE,
    TWO,
}

const {ccclass, property} = cc._decorator;
@ccclass
export class HintUI extends DialogBaseUI {
    @property(cc.Label)
    bodyLabel:cc.Label = null;
    @property(cc.Node)
    okNode:cc.Node = null;
    @property(cc.Node)
    cancelNode:cc.Node = null;
    callback = null;

    static hintQueue = [];
    static show(body:string,type?:HINT_TYPE,callback?){
        console.log(body,type);
        let node = cc.find("Canvas/提示框");
        if(!node) return;
        let component = node.getComponent(HintUI)
        if(!component) return;
        if(callback == null) callback = function () {};
        HintUI.hintQueue.push({body:body,type:type,callback:callback});
        component._showNext();
    }

    private _showNext(){
        let cache = HintUI.hintQueue[0];
        if(cache == null){
            this.node.active = false;
            return;
        }
        this.node.active =true;
        this.bodyLabel.string = cache.body;
        if(cache.type == HINT_TYPE.ONE || cache.type == null){
            this.cancelNode.active = false;
        }else if(cache.type == HINT_TYPE.TWO){
            this.okNode.active = true;
            this.cancelNode.active = true;
        }
    }

    onClick(event,data){
        let cache = HintUI.hintQueue.shift();
        cache.callback(data=="ok");
        this._showNext();
    }

    onDestroy(){
        HintUI.hintQueue = [];
    }
}